package com.yangyouli.unity_demo_server.controller;

import java.util.Date;

import com.alibaba.fastjson.JSONObject;
import com.yangyouli.unity_demo_server.annotation.Inject;
import com.yangyouli.unity_demo_server.annotation.ResponseClass;
import com.yangyouli.unity_demo_server.annotation.ResponseMethod;
import com.yangyouli.unity_demo_server.entity.User;
import com.yangyouli.unity_demo_server.server.serializeModel.ChatData;
import com.yangyouli.unity_demo_server.service.UserService;
import com.yangyouli.unity_demo_server.util.ThreadLocalHelper;

@ResponseClass("chat")
public class ChatController {

	@Inject
	private UserService userService;
	
	/**
	 * 某人在世界发言
	 * @param data 发言
	 * @return
	 */
	@ResponseMethod("chatInWorld")
	public String chatInWorld (String data) {
		User user = userService.findById(ThreadLocalHelper.getClient().getUserId());
		ChatData chatData = new ChatData(user.getNickname(), data, new Date().getTime());
		return JSONObject.toJSONString(chatData);
	}
	
	/**
	 * 某人在房间发言
	 * @param data 发言
	 * @return
	 */
	@ResponseMethod("chatInRoom")
	public String chatInRoom (String data) {
		User user = userService.findById(ThreadLocalHelper.getClient().getUserId());
		ChatData chatData = new ChatData(user.getNickname(), data, new Date().getTime());
		return JSONObject.toJSONString(chatData);
	}
}
